<?php 

class MatchDetailsLeaverVotes{

	function getLeaverData($matchID){
		$ret = array();
		$DB = new DB();
		$con = $DB->conDB();

		if($matchID > 0){
			$sql = "SELECT VoteForPlayer
					FROM MatchDetailsLeaverVotes
					WHERE MatchID = ".(int) $matchID."
							";
			$data = $DB->multiSelect($sql);

			if(is_array($data) && count($data) > 0){
				// array in richtige Formn bringen
				foreach($data as $k => $v){
					$dataCountable[] = $v['VoteForPlayer'];
				}
				$countArray = array_count_values($dataCountable);
				$ret['countArray'] = $countArray;
				$ret['status'] = true;
			}
			else{
				$ret['status'] = "SQL wrong";
			}
		}
		else{
			$ret['status'] = "matchID = 0";
		}

		return $ret;

	}

	function getLeaverVoteCount($matchID){
		$ret = array();
		$DB = new DB();
		$con = $DB->conDB();

		if($matchID > 0){
			$sql = "SELECT VoteForPlayer
					FROM `MatchDetailsLeaverVotes`
					WHERE MatchID = ".(int)$matchID." AND Vote != 0
							";
			$count = $DB->countRows($sql);

			$ret['count'] = $count;
			$ret['status'] = true;
		}
		else{
			$ret['status'] = "matchID = 0";
		}

		return $ret;
	}

	function insertSelectedLeaver($matchID, $leaver, $steamID){
		$ret = array();
		$DB = new DB();
		$con = $DB->conDB();
		$ret['debug'] = print_r($leaver,1);
		if($matchID > 0){
			if(is_array($leaver) && count($leaver)>0){
				$ret['debug'] .= "#### LEAVER angegeben ####";
				foreach($leaver as $k => $v){
					$ret['debug'] .= "LEAVER: ".$v;

					$insertArray = array();

					$insertArray['steamID'] = secureNumber($steamID);
					$insertArray['matchID'] = (int) $matchID;
					$insertArray['VoteForPlayer'] = secureNumber($v);
					$insertArray['Timestamp'] = time();

					$DB->insert("MatchDetailsLeaverVotes", $insertArray);
				}
				$ret['status'] = true;
			}
			else $ret['status'] = "Leaver ist null";
		}
		else{
			$ret['status'] = "matchID = 0";
		}
		return $ret;
	}

}

?>